package com.huangpeng.designmodel.responsibility;

import com.huangpeng.designmodel.entity.Goods;
import com.huangpeng.designmodel.entity.Tax;

import java.util.List;

/**
 * @Author huangpeng
 * @Title 责任链接口实现类
 * @Package
 * @Date 2020/10/21 14:21
 * @Description 责任链接口实现类
 * @Version 1.0
 */
public class ReceiptHandleChain implements IReceiptHandleChain {
    //记录当前处理者位置
    private int index = 0;
    //处理者集合
    private static List<IReceiptHandler> receiptHandlerList;
    static {
        //从容器中获取处理对象
        receiptHandlerList = ReceiptHandlerContainer.getReceiptHandlerList();
    }
    @Override
    public void handleReceipt(Tax tax, List<Goods> list) {
        if(receiptHandlerList != null && !receiptHandlerList.isEmpty()){
            if(index != receiptHandlerList.size()){
                IReceiptHandler receiptHandler = receiptHandlerList.get(index++);
                receiptHandler.handleReceipt(tax,list,this);
            }
        }
        System.out.println("################index=" + index);
    }
}
